package com.tool4j.controller;

import com.tool4j.util.http.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

@RestController
@Slf4j
@RequestMapping("/api/document")
public class DocumentController {

    @Value("classpath:template-help.md")
    private Resource resource;

    @GetMapping("templateDoc")
    public Result<String> getHelpDocument() {
        try (InputStream inputStream = resource.getInputStream()) {
            String content = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
            return Result.ok(content);
        } catch (IOException e) {
            log.error("读取文档失败", e);
        }
        return Result.ok("");
    }

}
